package com.tuzhi.common.domain;

import com.tuzhi.common.constants.ResultConstant;

import java.io.Serializable;

public class ResultBO<E> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String code;
    private String msg;

    private E data;

    public ResultBO() {
    }

    public ResultBO(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultBO(String code, String msg, E data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public ResultBO setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ResultBO setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public E getData() {
        return data;
    }

    public ResultBO setData(E data) {
        this.data = data;
        return this;
    }

    public <T extends ResultBO> T ofRc(ResultConstant.RC rc) {
        this.code = rc.getCode();
        this.msg = rc.getMsg();
        return (T) this;
    }

    public <T extends ResultBO> T ofRC(ResultConstant.RC rc) {
        this.code = rc.getCode();
        this.msg = rc.getMsg();
        return (T) this;
    }

    public <T extends ResultBO> T ofCode(String code) {
        this.code = code;
        return (T) this;
    }

    public <T extends ResultBO> T ofMsg(String msg) {
        this.msg = msg;
        return (T) this;
    }

    public <T extends ResultBO> T ofData(E data) {
        this.data = data;
        return (T) this;
    }

    public <T extends ResultBO> T of(String code, String msg, E data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        return (T) this;
    }

    public boolean isSuccess() {
        return ResultConstant.SUCCESS.getCode().equals(code);
    }

}
